#/***************************************************************************\
# * Copyright (C) by Keio University
# * CMakeLists.txt created in 10 2011.
# * Mail : fdesorbi@hvrl.ics.keio.ac.jp
# *
# * This file is part of the HVRL Engine Library.
# *
# * The HVRL Engine Library is free software; you can redistribute it and/or modify
# * it under the terms of the GNU Lesser General Public License as published by
# * the Free Software Foundation; either version 3 of the License, or
# * (at your option) any later version.
# *
# * The HVRL Engine Library is distributed in the hope that it will be useful,
# * but WITHOUT ANY WARRANTY; without even the implied warranty of
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# * GNU Lesser General Public License for more details.
# *
# * You should have received a copy of the GNU Lesser General Public License
# * along with this program.  If not, see <http://www.gnu.org/licenses/>.
# *
# ***************************************************************************/

PROJECT(HVRL_SAMPLE_GPU_UNDISTORT_BILINEAR_FILTERING)

   INCLUDE_DIRECTORIES(
        "../../../modules/common/include"
        "../../../modules/video/include"
        "../../../modules/opengl/include"
        "../../../modules/tools/include"
        "../../../modules/gpgpu/include"
    )

	set(the_target "gpu_undistortbilinear")

	file(GLOB cpp_samples RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp)
	file(GLOB hpp_samples RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.hpp)

if (CUDA_FOUND)

    if (UNIX OR APPLE)
        set (CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS}  "-Xcompiler;-fPIC;")
        #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" "-fPIC")
    endif()

    #set (CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} "-keep")
    #set (CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} "-Xcompiler;/EHsc-;")

    if (APPLE)
        set (CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} "-Xcompiler;-fno-finite-math-only;")
    endif()


    string(REPLACE "/W4" "/W3" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
    string(REPLACE "/W4" "/W3" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
    string(REPLACE "/W4" "/W3" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")

    if(MSVC)
        #string(REPLACE "/W4" "/W3" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
        #string(REPLACE "/W4" "/W3" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
        #string(REPLACE "/W4" "/W3" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4211 /wd4201 /wd4100 /wd4505 /wd4408")

        string(REPLACE "/EHsc-" "/EHs" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
        string(REPLACE "/EHsc-" "/EHs" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
        string(REPLACE "/EHsc-" "/EHs" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
        string(REPLACE "/EHsc-" "/EHs" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
        string(REPLACE "/EHsc-" "/EHs" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
        string(REPLACE "/EHsc-" "/EHs" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
    endif()
    CUDA_COMPILE(cuda_objs ${lib_cuda})

endif()
	CUDA_ADD_EXECUTABLE (${the_target} ${cpp_samples} ${hpp_samples} ${cuda_objs})

        set_target_properties(${the_target} PROPERTIES
            OUTPUT_NAME "${the_target}"
            PROJECT_LABEL "(SAMPLE) ${the_target}")
        add_dependencies(${the_target} ${OpenCV_LIBS} ${CUDA_LIBRARIES} ${FREEGLUT_LIBRARIES} hvrl_common hvrl_tools hvrl_opengl hvrl_gpgpu)
        target_link_libraries(${the_target} ${OpenCV_LIBS} ${CUDA_LIBRARIES} ${FREEGLUT_LIBRARIES} hvrl_common hvrl_tools hvrl_opengl hvrl_gpgpu)

if (CUDA_FOUND)
    target_link_libraries(${the_target} ${CUDA_LIBRARIES})
    CUDA_ADD_CUFFT_TO_TARGET(${the_target})

    unset(CUDA_npp_LIBRARY CACHE)
    find_cuda_helper_libs(npp)
    target_link_libraries(${the_target} ${CUDA_npp_LIBRARY})
endif()

 	install(TARGETS ${the_target}
                RUNTIME DESTINATION "${HVRL_BIN_INSTALL_PATH}/samples/${the_target}" COMPONENT main)

